var g = Graphics.createArrayBuffer(16,16,8);
g.dump = _=>{
  var s = "";
  var b = new Uint8Array(g.buffer);
  var n = 0;
  for (var y=0;y<g.getHeight();y++) {
    s+="\n";
    for (var x=0;x<g.getWidth();x++) 
      s+=".-+#"[b[n++]&3];
  }
  return s;
}
g.print = _=>{
  print("`"+g.dump()+"`");
}
var ok = true;
function SHOULD_BE(a) {
  var b = g.dump();
  if (a!=b) {
    console.log("GOT :"+b+"\nSHOULD BE:"+a+"\n================");
    ok = false;
  }
}

var img = {
  width : 8, height : 8, bpp : 8,
  buffer : new Uint8Array([
    3,3,3,3,3,3,3,3,
    3,3,3,3,3,3,3,3,
    3,1,1,1,1,1,1,3,
    3,1,1,1,1,1,1,3,
    3,1,1,1,1,1,1,3,
    3,1,1,1,1,1,1,3,
    3,1,1,1,1,1,1,3,
    3,3,3,3,3,3,3,3,
  ]).buffer
};

g.clear().drawImage(img,4,4,{rotate:-0.000000001});
SHOULD_BE(`
########........
########........
#------#........
#------#........
#------#........
#------#........
#------#........
########........
................
................
................
................
................
................
................
................`);

g.clear().drawImage(img,4,4,{rotate:Math.PI/2});
SHOULD_BE(`
########........
#-----##........
#-----##........
#-----##........
#-----##........
#-----##........
#-----##........
########........
................
................
................
................
................
................
................
................`);


g.clear().drawImage(img,4,4,{rotate:Math.PI});
SHOULD_BE(`
########........
#------#........
#------#........
#------#........
#------#........
#------#........
########........
########........
................
................
................
................
................
................
................
................`);


g.clear().drawImage(img,4,4,{rotate:Math.PI*3/2});
SHOULD_BE(`
########........
##-----#........
##-----#........
##-----#........
##-----#........
##-----#........
##-----#........
########........
................
................
................
................
................
................
................
................`);

result = ok;
